//
//  YSTabBarController.m
//  YSKitDemo
//
//  Created by MOLBASE on 2018/8/15.
//  Copyright © 2018年 YangShen. All rights reserved.
//

#import "YSTabBarController.h"
#import "YSDemoListViewController.h"
#import "YSAnimateViewController.h"
#import "YSNavigationController.h"

@interface YSTabBarController () <UITabBarControllerDelegate>

@end

@implementation YSTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];    
    [self addChildViewControllers];
    [self addTabarItems];
    self.delegate = self;
}

- (void)addChildViewControllers {

    YSNavigationController *one = [[YSNavigationController alloc] initWithRootViewController:[YSDemoListViewController new]];
    YSNavigationController *two = [[YSNavigationController alloc] initWithRootViewController:[YSAnimateViewController new]];

    self.viewControllers = @[one, two];
}

- (void)addTabarItems {
    NSArray *titles = @[@"DemoList", @"Animated"];

    [self.childViewControllers enumerateObjectsUsingBlock:^(__kindof UIViewController * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        obj.tabBarItem.title = titles[idx];
//        obj.tabBarItem.image = [UIImage imageNamed:tabBarItemsAttributes[idx][@"TabBarItemImage"]];
//        obj.tabBarItem.selectedImage = [UIImage imageNamed:tabBarItemsAttributes[idx][@"TabBarItemSelectedImage"]];
        obj.tabBarItem.titlePositionAdjustment = UIOffsetMake(0, -3);
    }];

    self.tabBar.tintColor = [UIColor redColor];
}

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController {
    return YES;
}

@end
